<extend name="layout/edit" />

<block name="HEADER">
	<style type="text/css">
		/*.xw-searchQuery{ display: none; }*/
	</style>
</block>

<block name="CONTENT">
	<div style="height: calc(100% - 42px);">
		<control:grid id="editGrid" />
	</div>
    <div class="xw-form">
		<div class="xw-btnRow" style="text-align: right;">
			<button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="page.save()" >
				保存
			</button> 
			<button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="$.close()">
				关闭
			</button>
		</div>
	</div>
</block>

<block name="FOOTER">
   <script type="text/javascript">
    var  page=(function(ns){
    	
		ns.init = function(){
			
		}
		
		ns.addIndex = 0;
		
		ns.addRow = function(){
			var data = editGrid.$search.getData()[0];
        	if(!data){
				$.toast(0,'请先选择门店！');
				return false;
			}
        	var shop_id = data['value'];
			$.ajaxs("/admin/v1/shop_staff/getMaxId").then(function(res){
				ns.addIndex = (ns.addIndex || res.data)+1;
				editGrid.addRow([{
					bank_code: "",
					bank_name: "",
					base_pay: "0",
					base_yj: "0",
					code: "s-"+shop_id+"-"+ns.addIndex,
					entry_time: $.getDate("yyyy-MM-dd HH:mm:ss"),
					gh:('000'+ ns.addIndex).slice(-3),
					idcard: null,
					img: null,
					is_del: 0,
					mail: null,
					name: "",
					phone: "",
					shop_id: shop_id,
					status: 1,
					work_type: "",
					password:'1'
				}]);
			});
		}
		
		ns.deleteRow = function(){
			$.confirm("确定删除？",function(index){
				editGrid.deleteRow();    
				layer.close(index);
	    	});
		}
    
        //保存
        ns.save=function(){
        	var data = editGrid.$search.getData()[0];
        	if(!data){
				$.toast(0,'请先选择门店！');
				return false;
			}
        	if( editGrid.verification() ){
        		var shop_id = data['value'];
	        	$.ajaxs('/admin/v1/shop_staff/add',{
	        		shop_id:shop_id,
	        		data:JSON.stringify(editGrid.getRows())
	        	}).then(function(res){
	        		$.toast(1,"保存成功！");
	        		editGrid.load();
	        		parent.grid.load();
	        	});
        	}
        }
        
        return ns;
    }({}));
    
    $(function(){ page.init(); });
   </script>
</block>



